﻿using LiteBlog.Repositories.Common;
using LiteBlog.Repositories.Contracts;
using LiteBlog.Repositories.Framework;
using LiteBlog.Repositories;
using LiteBlog.Repositories.Mocks;
using Moq;
using StructureMap;
using StructureMap.Configuration.DSL;
using System;

namespace LiteBlog.IoC
{
    class RegistryForXmlLayerTests : Registry
    {
        internal RegistryForXmlLayerTests()
            : base()
        {
            
            For<IXmlHelper>().Use(() => Mock.Of<IXmlHelper>());
            For<IDataContext>().Singleton().Use<DataContext>();
            For<ArchiveRepository>().Use<ArchiveRepository>()
                              .Ctor<IXmlHelper>()
                              .Is(new Func<IContext, IXmlHelper>((c)
                                  => ArchiveDataMock.GetMock()));
            For<IBlogRepository>().Use<BlogRepository>();

            For<CategoryRepository>().Use<CategoryRepository>()
                               .Ctor<IXmlHelper>()
                               .Is(new Func<IContext, IXmlHelper>((c) => 
                                   CategoryDataMock.GetMock()));

            For<ICommentRepository>().Use<CommentRepository>();

            For<IPageRepository>().Use<PageRepository>();
            For<PostRepository>().Use<PostRepository>();
            For<PostCommentRepository>().Use<PostCommentRepository>();

            // This singleton on trial basis.
            For<DraftRepository>().Singleton()
                            .Use<DraftRepository>()
                            .Ctor<IXmlHelper>()
                            .Is(new Func<IContext, IXmlHelper>((c)
                                => DraftDataMock.GetMock()));

            For<SettingsRepository>().Use<SettingsRepository>()
                               .Ctor<IXmlHelper>()
                               .Is(new Func<IContext, IXmlHelper>((context) =>
                                   SettingsDataMock.GetMock()));

            For<StatRepository>().Use<StatRepository>()
                           .Setter<BlogRepository>()
                           .Is(new Func<IContext, BlogRepository>((context)
                               => Mock.Of<BlogRepository>()));

            For<TagRepository>().Use<TagRepository>()
                          .Ctor<IXmlHelper>()
                          .Is(new Func<IContext, IXmlHelper>((c)
                              => TagDataMock.GetMock()));
        }
    }
}
